package com.wh.util;

import org.springframework.util.StringUtils;

import java.util.UUID;

/**
 * @author: wh(1835734390 @ qq.com)
 * @date: 2022/11/15 22:01
 * @description:
 * @version:
 */
public class RandomNum {
    //UUID生成8位随机数
    public static String randomId(){
        String[] chars = new String[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G",
                "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
        StringBuffer shortBuffer = new StringBuffer();
        String uuid = UUID.randomUUID().toString().replace("-","");
        for (int j=0;j<8;j++) {
            String str=uuid.substring(j*4,j*4+4);
            int par=Integer.parseInt(str,16);
            shortBuffer.append(chars[par % 36]);
        }
        return shortBuffer.toString();
    }

    // 手机号码前三后四脱敏
    public static final String blurPhone(String phone) {
        if (StringUtils.isEmpty(phone) || (phone.length() != 11)) {
            return phone;
        }
        return phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
    }



}
